package com.ythook.mentor.repository;

import com.ythook.mentor.entity.Trainings;
import com.ythook.mentor.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<User,Long> {

    @Query(value = "select t from User t where (t.username=?1 or t.email=?1) and t.password=?2 and t.userStatus='1'")
    User login(String username, String password);

    @Query(value = "select distinct u.* from user u " +
            "left join mentor_skills s on u.id = s.mentor_id " +
            "left join technologies t on t.id = s.technology_id " +
            "left join mentor_calendar c on u.id = c.mentor_id " +
            "where if(IFNULL(?1, ''), c.end_date < ?1, 1=1) " +
            "and if(IFNULL(?2, ''), UPPER(t.name) LIKE BINARY CONCAT('%', UPPER(?2), '%'), 1=1)", nativeQuery = true)
    List<User> searchMentorByKey(Date startDate, String key);

}
